package crawler.chapter1;

/**
 * @author Darkness Shadow
 * @description: 海明距离
 * @date 2020/1/16 23:06
 */
public class HaiMingDistance {

    public static void main(String[] args) {
        System.out.println(haiMingDistance(2,5));
    }


    public static int haiMingDistance(int x, int y) {
        int dist = 0;//海明距离
        int val = x ^ y;//异或结果
        while (val > 0) {
            ++dist;
            val &= val - 1;//去掉val中最右边的一个1
        }
        return dist;
    }
}
